<form class="layui-form seller-form"  action="" >
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">促销名称：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="name" lay-verify="title" placeholder="请输入促销名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">启用状态：</label>
            <div class="layui-input-inline seller-inline-2">
                <select name="status" lay-verify="">
                    <option value=""></option>
                    <option value="1">开启</option>
                    <option value="2">关闭</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">是否排他：</label>
            <div class="layui-input-inline seller-inline-2">
                <select name="exclusive" lay-verify="">
                    <option value=""></option>
                    <option value="2">是</option>
                    <option value="1">否</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">起止时间：</label>
            <div class="layui-input-inline seller-inline-6">
                <input  type="text" name="date" value="" id="date" placeholder="请输入起止时间" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>筛选</button>
            <a href="{:url('Promotion/add')}" class="layui-btn layui-btn-sm option-add">
                <i class="layui-icon">&#xe608;</i> 添加
            </a>
        </div>
    </div>
</form>

<div class="table-body">
    <table id="promotion" lay-filter="test"></table>
</div>

<script>
    layui.use(['form', 'layedit', 'laydate','table'], function(){
        //时间插件
        layui.laydate.render({
            elem: '#date',
            range: '到',
            type: 'datetime'
        });

        //表格渲染
        var promotionTable = layui.table.render({
            elem: '#promotion',
            height: 'full-300',
            cellMinWidth: '80',
            page: 'true',
            limit:'{:config("jshop.page_limit")}',
            url: "{:url('promotion/index')}?_ajax=1",
            id:'promotion',
            cols: [[
                {type:'numbers'},
                {field:'name',title:'促销名称'},
                {field:'sort', width:140, sort: true,title:'权重'},
                {field:'status', width:100,title:'启用状态'},
                {field:'exclusive', width:100,title:'是否排他'},
                {field:'stime',width:170,title:'开始时间'},
                {field:'etime',width:170,title:'结束时间'},
                {field: 'operating', title: '操作', width:200, align: 'center',templet:function(data){
                    var html = '';
                    html += '<a  class="layui-btn layui-btn-xs" href="{:url('promotion/edit')}?id=' + data.id + '">编辑</a>';
                    html += '<a  class="layui-btn layui-btn-danger layui-btn-xs option-del" data-id="' + data.id + '" >删除</a>';
                    return html;
                }},
            ]]
        });
        layui.form.on('submit(*)', function(data){
            layui.table.reload('promotion', {
                where: data.field
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });


        //促销删除
        $(document).on('click','.option-del',function(){
            var id = $(this).attr('data-id');
            layer.confirm('您确定删除此促销信息？', {
                btn: ['确认','取消'] //按钮
            }, function(){
                //去删除
                JsPost("{:url('promotion/del')}",{'id':id},function(res){
                    if(res.status){
                        layer.msg('删除成功');
                        promotionTable.reload();
                    }else{
                        layer.msg(res.msg);
                    }
                });
            }, function(){
                layer.close(1);
            });
        });
    });
</script>
